<template>
	<view class="container">
		<empty v-if="announceDesc == ''"></empty>
		<view style="width:100%;height:100%" v-else>
			<rich-text :nodes="announceDesc" style="font-size: 28upx;"></rich-text>
			<view style="height: 120upx;width: 100%;background: #FBFBFB;"></view>
			<button type="primary" class="button_class" @click="goToEnroll()">前往应征报名</button>
		</view>
	</view>
</template>

<script>
	import empty from "@/components/empty";
	export default {
		data() {
			return {
				announceInfo: {},
				announceDesc: "",
				communityId: this.$api.util.getAreaCode()
			}
		},
		mounted() {
			this.getData()
		},
		components: {
			empty
		},
		methods: {
			getData() {
				let params = {
					"areaCode": this.communityId,
					"pageSize": 1,
					"page": 1,
					"activityType": "2", //参军活动
					"fromPhone": "1"
				}
				this.$api.request.queryActivities(params, (res) => {
					if (res.body.status.statusCode === '0') {
						let activities = res.body.data.lists;
						if (activities.length > 0) {
							this.announceInfo = activities[0].activity
							this.announceDesc = this.$api.htmlParser.parseHtml(this.announceInfo.activityDescribe)
						}
					} else {
						this.$api.msg("系统出错了")
					}
				})
			},
			goToEnroll() {
				if (this.announceDesc == "") {
					this.$api.msg("暂未发布征兵公告！")
					return;
				}
				let startTime = new Date(this.announceInfo.activityEnrollStartTime).getTime();
				let endTime = new Date(this.announceInfo.activtiyEnrollEndTime).getTime();
				let nowTime = new Date().getTime();
				if (startTime > nowTime) {
					this.$api.msg("活动还未开始")
					return;
				} else if (endTime < nowTime) {
					this.$api.msg("活动已经结束")
					return;
				}
				uni.navigateTo({
					url: "/package_isp/pages/conscription/apply"
				})
			},
		}
	}
</script>

<style>
	page {
		background-color: #FBFBFB;
	}

	.container {
		width: 100%;
		background-color: #FBFBFB;
		overflow: hidden;
	}

	.announce_text {
		padding: 32upx;
		font-size: 28upx;
	}

	.button_class {
		position: fixed;
		bottom: 40upx;
		margin-top: 20upx;
		width: 80%;
		margin-left: 10%;
		height: 80upx;
		line-height: 80upx;
		border-radius: 40upx;
		background-color: #8AB46C !important;
		color: white
	}
</style>
